	$(function() {

		$(window).resize(function(){
			$('.right-iframe').height($(window).height()-80);
		});
		 $(".table-container").resize(
				function() {
					
					console.info("width: "+$(".table-container").width());
					$("#contentGrid").setGridWidth($(".table-container").width()-1);
				}); 
		$(".widget-toolbar .btn-add").click(function() {
			var tree = window.top.byContentTree;
			var nodes = tree.getSelectedNodes();
			if(nodes.length>0){
	            	$(".right-iframe").attr("src","/content/form?subjectId="+nodes[0].id);
			}else{
				layer.msg("请选择所属的栏目！");
			}
            
			
		});
		$(".widget-toolbar .btn-update").click(function() {
			var grid = $("#contentGrid");
            var rowKey = grid.jqGrid('getGridParam',"selrow");
            if (!rowKey){
            	layer.msg('请选择一条记录！');
            	return;
            }
                
            $(".right-iframe").attr("src","/content/form?contentId="+rowKey);
		});

		$(".widget-toolbar .btn-delete").click(function() {
			var grid = $("#contentGrid");
            var rowKey = grid.jqGrid('getGridParam',"selrow");
            if (!rowKey){
            	layer.msg("请选择一条记录");
            	return;
            }
            
            $.ajax({
				url : "/content/deleteContent?contentId="+rowKey,
				type:"get",
				success : function(resp) {
					layer.msg("删除成功");
					$("#contentGrid").delRowData(rowKey);
				}
			});
		});
		jQuery('#contentGrid')
				.jqGrid(
						{
							//height : 600,
							autowidth : true,
							"hoverrows" : false,
							"viewrecords" : false,
							"gridview" : true,
							"editurl" : "clientArray",
							jsonReader : {
								root : "data"
							},
							"rowNum" : 10,
							"datatype" : "local",
							"colModel" : [
									{
										"name" : "id",
										"key" : true,
										"hidden" : true
									},
									{
										"name" : "title",
										"label" : "标题",
										"editable" : true
									},
									{
										"name" : "content",
										"label" : "内容",
										"editable" : true
									},
									{
										"name" : "summary",
										"label" : "概要",
										"editable" : true
									},
									{
										"name" : "summary_img",
										"label" : "图片",
										"editable" : true
									},
									{
										"name" : "status",
										"label" : "是否可用",
										formatter: 'checkbox',
									},

							],
							gridComplete:function(){
								console.info('=====gridComplete!=====');
							},
							"pager" : "#contentPager"
						});
		updatePagerIcons($('#jqGrid'));
		// nable add
		jQuery('#contentGrid').jqGrid('navGrid', '#contentPager', {
			"edit" : false,
			"add" : false,
			"del" : false,
			"search" : false,
			"refresh" : false,
			"view" : false,
			"excel" : false,
			"pdf" : false,
			"csv" : false,
			"columns" : false
		}, {
			"drag" : true,
			"resize" : true,
			"closeOnEscape" : true,
			"dataheight" : 150
		}, {
			"drag" : true,
			"resize" : true,
			"closeOnEscape" : true,
			"dataheight" : 150
		});
		
		
		byContentTreeSelectCallBack = function(event, treeId, treeNode){
			console.info(treeNode.name);
			$('#contentGrid').clearGridData();
			$('#contentGrid').setGridParam({url: "/content/listBySubjectId?subjectId="+treeNode.id,datatype: 'json'});
			$('#contentGrid').trigger("reloadGrid");
		}
	});
